package com.swallow.auth.domain.tenant.model;

import com.swallow.auth.common.enums.ErrorCode;
import com.swallow.auth.common.exception.BizException;
import com.swallow.auth.common.utils.SpringUtils;
import com.swallow.auth.domain.tenant.repository.ITenantDomainRepository;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author: 18310740596@163.com
 * @date: 2024-05-11 21:38:20
 * @version: v1.0
 * @describe: class responsibility
 */
@Builder
@Accessors(chain = true)
@Data
public class TenantEntity {
    private String tenantNo;

    private String tenantName;

    /**
     *  重复性校验
     */
    public void repeatCheck() {
        ITenantDomainRepository repository = SpringUtils.getBean(ITenantDomainRepository.class);

        if (repository.repeatCheck(this)) {
            throw new BizException(ErrorCode.DATA_HAS_EXITS, "租户");
        }
    }

    public void create() {
        ITenantDomainRepository repository = SpringUtils.getBean(ITenantDomainRepository.class);
        repository.createTenant(this);
    }
}
